﻿Imports System.Data.OleDb

Public Class ViewProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If User.Identity.IsAuthenticated = False Then       'The 'IsAuthenticated' is to valid user has authentication or not, and it will return 'true' or 'false'. 
            'In other word, it can valid user login or not.
            Response.Redirect("nonLoginViewProfile.aspx")    'If the user is not login, then take the user to the page of 'nonLoginViewProfile.aspx'
        ElseIf User.Identity.Name = Request.QueryString("dinerID") Then
            Response.Redirect("MyProfile.aspx?dinerID=" & User.Identity.Name)       'If the user click their own name or protrait, it can take user to 'MyProfile.aspx'
        Else
            Dim sql As String = "SELECT * FROM UserProfile WHERE dinerID=@f1"        'This is an SQL statment
            Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("SpiritConnString").ConnectionString)       'Connect to the Database
            Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)

            conn.Open()
            cmd.Parameters.AddWithValue("@f1", Request.QueryString("dinerID"))      'I dont user User.Identity.Name, because if I do that, no mater which profile the user want to see, the 'Label' can only show the user's name, not other user's name
            Dim datebaseReader = cmd.ExecuteReader()

            datebaseReader.Read()

            If Not IsDBNull(datebaseReader("firstName")) Then
                lb_profile.Text = datebaseReader("firstName")
            End If

            If Not IsDBNull(datebaseReader("firstName")) Then
                lb_comment.Text = datebaseReader("firstName")
            End If

            If Not IsDBNull(datebaseReader("firstName")) Then
                lb_upload.Text = datebaseReader("firstName")
            End If

            datebaseReader.Close()
            conn.Close()
        End If
    End Sub

End Class